
<body>
    <div class="x-body">
        <form class="layui-form layui-form-pane">
            <div class="layui-form-item">
                <label for="L_title" class="layui-form-label">
                    标题
                </label>
                <div class="layui-input-block">
                    <input type="text" id="L_title" name="title" required  lay-verify="title"
                    autocomplete="off" class="layui-input">
                </div>
            </div>
            <div class="layui-form-item layui-form-text">
                <div class="layui-input-block">
                    <textarea id="L_content" required  name="content" 
                    placeholder="请输入内容" class="layui-textarea fly-editor" style="height: 260px;"></textarea>
                </div>
                <label for="L_content" class="layui-form-label" style="top: -2px;">
                    描述
                </label>
            </div>
            <div class="layui-form-item">
                <button class="layui-btn" lay-filter="add" lay-submit>
                    立即发布
                </button>
            </div>
        </form>
    </div>
    <script>
    layui.use(['layer', 'form','layedit'], function(){
      var layer = layui.layer,form = layui.form(),
      layedit = layui.layedit;
      layedit.set({
        uploadImage: {
          url: '{:U("admin/newsadd/upload")}' //接口url
          ,type: '' //默认post
        }
      });
      index = layedit.build('L_content');
       $ = layui.jquery;
       form.verify({
          title: function(value){
            if(value.length < 10){
              return '标题至少得10个字符啊';
            }
          }
        })
      form.on('submit(add)', function(data){
       data.field.content=layedit.getContent(index);
        $.ajax({
        url:'{:U("admin/newsadd/add")}',
          type: 'POST',
          dataType: 'json',
          data: data.field,
        })
        .done(function(respones) {
          if(respones.error==1){
              layer.alert(respones.info,{icon:1},function (){
                    
                });
          }else{
                layer.alert(respones.info,{icon:6},function (){
                    layer.closeAll();
                    parent.location.reload();
                });
          }
        })
        .fail(function() {
          console.log("error");
        });

        return false;
       });
    });
    </script>
    <script>
    var _hmt = _hmt || [];
    (function() {
      var hm = document.createElement("script");
      hm.src = "https://hm.baidu.com/hm.js?b393d153aeb26b46e9431fabaf0f6190";
      var s = document.getElementsByTagName("script")[0]; 
      s.parentNode.insertBefore(hm, s);
    })();
    </script>
</body>
